//复写零
public class demo10 {
    public void duplicateZeros(int[] arr) {
        //双指针找到最后一个零的位置
        int cur = 0,dest = -1;
        int n = arr.length;
        while(cur < n){
            if(arr[cur] == 0) dest += 2;
            else dest += 1;
            if (dest >= n-1) break;
            cur++;
        }
        //处理边界问题
        if(dest == n){
            arr[n-1] = 0;
            dest -= 2;
            cur--;
        }
        //从后往前复写
        while(cur >= 0){
            if (arr[cur] != 0) arr[dest--] = arr[cur--];
            else if (arr[cur] == 0){
                arr[dest--] = 0;
                arr[dest--] = 0;
                cur--;
            }
        }
    }
}
